﻿@model IEnumerable<BenzInfo.Hockey.Grenadiers.Models.Game>

@{
    ViewBag.Title = "Index";
}

<script type="text/javascript">

    $(document).ready(function () {

        $('#dialog_games').dialog({
            autoOpen: false,
            modal: true,
            draggable: false,
            resizable: false,
            width: 580,
            height: 'auto',
            buttons: [
                {
                    id: 'dialog_btn_save', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save',
                    click: function () {
                        $('form', this).submit();
                    }
                },
                {
                    id: 'dialog_btn_cancel', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Cancel',
                    click: function () {
                        $(this).dialog('close');
                    }
                }
            ]
        });

        $('a.buttons').click(function () {
            var url = $(this).attr('href');
            var title = '';

            if (url.indexOf('Create') > 0) {
                title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Create';
                $('#dialog_btn_save span').html(title);
            }
            else if (url.indexOf('Edit') > 0) {
                title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit';
                $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save');
            }
            else if (url.indexOf('Delete') > 0) {
                title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Delete';
                $('#dialog_btn_save span').html(title);
            }

            $('#dialog_games').empty().load(url, function () {
                $('#dialog_games').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });

    });

</script>

<h2>Index</h2>

<div id="dialog_games"></div>

@if (ViewBag.CurrentUser != null)
{             
  <div>
  	<span class="buttons">  
    	@Html.ActionLink("Create New", "Create", null, new { @class = "buttons" })
  	</span>
  </div>
}	      
<table>
    <tr>
        <th>Title</th>
        <th>Home Score</th>
        <th>Away Score</th>
        <th>Ending Value</th>
        <th>Date Start</th>
        <th>Date End</th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @if (ViewBag.Lang == "fr")
            {
                @Html.DisplayFor(modelItem => item.TitleFR)
            }
            else
            {
                @Html.DisplayFor(modelItem => item.TitleEN)
            }
        </td>
        <td> @Html.DisplayFor(modelItem => item.HomeScore)</td>
        <td> @Html.DisplayFor(modelItem => item.AwayScore)</td>
        <td> @Html.DisplayFor(modelItem => item.EndingValue)</td>
        <td>@Html.DisplayFor(modelItem => item.DateStart)</td>
        <td>@Html.DisplayFor(modelItem => item.DateEnd)</td>
        <td>
        @if (ViewBag.CurrentUser != null)
        {             
	        <div>
	        	<span class="buttons">        
	            @Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "buttons" }) |
	            @Html.ActionLink("Delete", "Delete", new { id = item.Id }, new { @class = "buttons" })
	        	</span>
	        </div>
	      }	            
        </td>
    </tr>
}

</table>
